package com.starsoft.smdc.dao;

import java.util.Date;

import org.springframework.stereotype.Repository;

import com.starsoft.frame.core.orm.BaseDao;
import com.starsoft.smdc.bean.SmdcHoliday;
import com.starsoft.smdc.bean.SmdcHolidayDetail;

@Repository
public class HolidayDao extends BaseDao<SmdcHoliday, String>{
	
	public SmdcHoliday getdefault(){
		return this.get("default");
	}
	
	public SmdcHolidayDetail getdefault(Date date){
		SmdcHoliday holiday = this.get("CHN");
		return holiday.getDetail(date);
	}
	
	public void insert(Date date, boolean isHoliday){
		SmdcHoliday holiday = this.get("CHN");
		SmdcHolidayDetail detail = this.getdefault(date);
		if(detail!=null){
			detail.setIsHoliday(isHoliday);
		} else {
			detail = new SmdcHolidayDetail(holiday, date, isHoliday);
		}
		this.saveOrUpdate(detail);
	}
}
